#!/bin/sh

### Sets up an enviroment for calling the makefile that compiles
### freeGSD.

# These are the important vars to pass to make
ARCH=
C_FLAGS=
ASM_FLAGS=
LD_FLAGS=

# Flags for i386
i386_ARCH="i386"
i386_C_FLAGS="-march=athlon-fx -m32 -Wall -c -ffreestanding"
i386_ASM_FLAGS="-f elf32 -a x86"
i386_LD_FLAGS="-nostdlib -Tlink.ld.i386 -Map kernel.map"

# Flags for x86-64
x86_64_ARCH="x86-64"
x86_64_C_FLAGS=
x86_64_ASM_FLAGS=
x86_64_LD_FLAGS=


if [ $# -eq 0 -o $# -gt 1 ]; then
    echo "Usage: "
    echo "  ./compile.sh <i386|x86-64>"
    exit 1;
elif [ "$1" != "i386" -a "$1" != "x86-64" ]; then
    echo "Usage: "
    echo "  ./compile.sh <i386|x86-64>"
    exit 1;
fi

if [ "$1" = "i386" ]; then
    echo "Compiling freeGSD for i386 architecture"
    ARCH="ARCH=i386"
    export C_FLAGS=$i386_C_FLAGS
    export ASM_FLAGS=$i386_ASM_FLAGS
    export LD_FLAGS=$i386_LD_FLAGS
elif [ "$1" = "x86-64" ]; then
    ARCH="ARCH=x86-64"
    export C_FLAGS=$x86_64_C_FLAGS
    export ASM_FLAGS=$x86_64_ASM_FLAGS
    export LD_FLAGS=$x86_64_LD_FLAGS
fi

# The makefile then uses the exported flags variables.
/usr/bin/make -f Makefile.mk $ARCH
